﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ScheduleUI.aspx.cs" Inherits="ISSMoviePlex.Admin.ScheduleUI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:GridView ID="ScheduleGridView" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" CellPadding="4" DataSourceID="ScheduleDataSource" 
        ForeColor="#333333" GridLines="None" DataKeyNames="ScheduleId">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="ScheduleId" HeaderText="ScheduleId" 
                SortExpression="ScheduleId" Visible="False" />
            <asp:BoundField DataField="Movie.MovieName" HeaderText="Movie" 
                SortExpression="MovieId" />
            <asp:BoundField DataField="RoomId" HeaderText="Room" SortExpression="RoomId" />
            <asp:BoundField DataField="ShowTime" 
                HeaderText="Show Time" SortExpression="ShowTime" />
            <asp:BoundField DataField="TicketPrice" HeaderText="Ticket Price" 
                SortExpression="TicketPrice" DataFormatString="SGD {0}" />
            <asp:BoundField DataField="SeatAvailable" HeaderText="Seat Available" 
                SortExpression="SeatAvailable" />
        </Columns>
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
    <asp:ObjectDataSource ID="ScheduleDataSource" runat="server" 
        DataObjectTypeName="ISSMoviePlex.DAL.Models.Schedule" 
        DeleteMethod="DeleteSchedule" InsertMethod="AddSchedule" 
        SelectMethod="GetAllSchedules" TypeName="ISSMoviePlex.BLL.ScheduleBLL" 
        UpdateMethod="UpdateSchedule"></asp:ObjectDataSource>
    <br />
    <br />
    Schedule Details<br />
    <br />
    <asp:DetailsView ID="ScheduleDetailsView" runat="server" 
        AutoGenerateRows="False" CellPadding="4" DataKeyNames="ScheduleId" 
        DataSourceID="ScheduleDetailsDataSource" ForeColor="#333333" GridLines="None" 
        Height="50px" Width="500px">
        <AlternatingRowStyle BackColor="White" />
        <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
        <EditRowStyle BackColor="#2461BF" />
        <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
        <Fields>
            <asp:BoundField DataField="ScheduleId" HeaderText="ScheduleId" 
                InsertVisible="False" SortExpression="ScheduleId" Visible="False" />
            <asp:TemplateField HeaderText="Movie" SortExpression="MovieId">
                <EditItemTemplate>
                    <asp:DropDownList ID="MovieList" runat="server" 
                        DataSourceID="MovieListDataSource" DataTextField="MovieName" 
                        DataValueField="MovieId" SelectedValue='<%# Bind("MovieId") %>' >
                    </asp:DropDownList> 
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="MovieList" runat="server" 
                        DataSourceID="MovieListDataSource" DataTextField="MovieName" 
                        DataValueField="MovieId" SelectedValue='<%# Bind("MovieId") %>' >
                    </asp:DropDownList>                  
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="MovieLabel" runat="server" Text='<%# Bind("Movie.MovieName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Room" SortExpression="RoomId">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="RoomDataSource" DataTextField="RoomId" DataValueField="RoomId" 
                        SelectedValue='<%# Bind("RoomId") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="RoomList" runat="server" DataSourceID="RoomDataSource" 
                        DataTextField="RoomId" DataValueField="RoomId" 
                        SelectedValue='<%# Bind("RoomId") %>'>
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("RoomId") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Show Time" SortExpression="ShowTime">
                <EditItemTemplate>
                    <asp:TextBox ID="tbShowtime" runat="server" Text='<%# Bind("ShowTime", "{0:yyyy-MM-ddTHH:mm:ss}") %>' 
                        TextMode="DateTimeLocal"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                        ControlToValidate="tbShowtime" CssClass="failureNotification" Display="Dynamic" 
                        ErrorMessage="Please enter Showtime"></asp:RequiredFieldValidator>
                    <asp:CustomValidator ID="CustomValidator2" runat="server" 
                        ClientValidationFunction="validateShowTime" ControlToValidate="tbShowtime" 
                        CssClass="failureNotification" Display="Dynamic" 
                        ErrorMessage="Please enter a time in the future at least 1 week from now" 
                        onservervalidate="ValidateShowTime"></asp:CustomValidator>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="tbShowtime" runat="server" Text='<%# Bind("ShowTime") %>' 
                        TextMode="DateTimeLocal"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                        ControlToValidate="tbShowtime" CssClass="failureNotification" Display="Dynamic" 
                        ErrorMessage="Please enter Showtime"></asp:RequiredFieldValidator>
                    <asp:CustomValidator ID="CustomValidator1" runat="server" 
                        ControlToValidate="tbShowtime" CssClass="failureNotification" Display="Dynamic" 
                        ErrorMessage="Please enter a time in the future at least 1 week from now" 
                        onservervalidate="ValidateShowTime" 
                        ClientValidationFunction="validateShowTime"></asp:CustomValidator>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("ShowTime") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Ticket Price" SortExpression="TicketPrice">
                <EditItemTemplate>
                    <asp:TextBox ID="tbTicketPrice" runat="server" 
                        Text='<%# Bind("TicketPrice") %>' TextMode="Number"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                        ControlToValidate="tbTicketPrice" CssClass="failureNotification" 
                        Display="Dynamic" ErrorMessage="Please enter Ticket Price"></asp:RequiredFieldValidator>
                    <asp:RangeValidator ID="RangeValidator2" runat="server" 
                        ControlToValidate="tbTicketPrice" CssClass="failureNotification" 
                        Display="Dynamic" ErrorMessage="Please enter a number between 5 and 100" 
                        MaximumValue="100" MinimumValue="5" Type="Double"></asp:RangeValidator>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="tbTicketPrice" runat="server" 
                        Text='<%# Bind("TicketPrice", "SGD {0}") %>' TextMode="Number"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                        ControlToValidate="tbTicketPrice" CssClass="failureNotification" 
                        Display="Dynamic" ErrorMessage="Please enter Ticket Price"></asp:RequiredFieldValidator>
                    <asp:RangeValidator ID="RangeValidator1" runat="server" 
                        ControlToValidate="tbTicketPrice" CssClass="failureNotification" 
                        Display="Dynamic" ErrorMessage="Please enter a number between 5 and 100" 
                        MaximumValue="100" MinimumValue="5" Type="Double"></asp:RangeValidator>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" 
                        Text='<%# Bind("TicketPrice", "SGD {0}") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="SeatAvailable" HeaderText="Seat Available" 
                SortExpression="SeatAvailable" InsertVisible="False" ReadOnly="True" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                ShowInsertButton="True" />
        </Fields>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
    </asp:DetailsView>
    <asp:ObjectDataSource ID="ScheduleDetailsDataSource" runat="server" 
        DataObjectTypeName="ISSMoviePlex.DAL.Models.Schedule" 
        DeleteMethod="DeleteSchedule" InsertMethod="AddSchedule" 
        SelectMethod="GetSchedule" TypeName="ISSMoviePlex.BLL.ScheduleBLL" 
        UpdateMethod="UpdateSchedule">
        <SelectParameters>
            <asp:ControlParameter ControlID="ScheduleGridView" DefaultValue="1" 
                Name="ScheduleId" PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="MovieListDataSource" runat="server" SelectMethod="GetAllMovies"
        TypeName="ISSMoviePlex.BLL.MovieBLL"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="RoomDataSource" runat="server" 
        SelectMethod="GetAllRooms" TypeName="ISSMoviePlex.BLL.RoomBLL">
    </asp:ObjectDataSource>

    <script type="text/javascript">
        function validateShowTime(oSrc, args) {
            var today = new Date();
            today.setDate(today.getDate() + 7);
            var showTime = Date.parse(args.Value) + today.getTimezoneOffset() * 60000;
            args.IsValid = (new Date(showTime) >= today);
        }
    </script>
</asp:Content>


